package com.zhdl.modules.prefiresys.web.service;

import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.RandomUtil;
import com.google.common.eventbus.Subscribe;
import com.zhdl.common.eventbus.center.EventBusCenter;
import com.zhdl.common.eventbus.event.PreFireEvent;
import com.zhdl.common.ytools.ByteHelper;
import com.zhdl.common.ytools.DateTimeHelper;
import com.zhdl.common.ytools.FloatHelper;
import com.zhdl.modules.prefiresys.task.CollectDetector;
import com.zhdl.modules.prefiresys.task.PrefireWarnTaskDemo;
import com.zhdl.network.prefirertu.dto.UpsFrameDto;
import com.zhdl.network.prefiretcp.before.MemDevice;
import com.zhdl.network.prefiretcp.dto.FireDto;
import com.zhdl.network.service.conf.PortConf;
import com.zhdl.network.service.dto.FireParameter;
import com.zhdl.network.service.dto.SingleParaInfo;
import com.zhdl.network.service.dto.SysHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.zhdl.modules.prefiresys.web.service.CollectService.currentTime;

@Slf4j
@Component
public class EventBusResult {

    /**
     * ups模式, 电池电量
     */
    public static int upsMode = -1, upsBattery = -1;

    /**
     * 探测器参数
     */
//    public static FireParameter allPara66 = new FireParameter();
    public static Map<Byte, Byte> allPara9B = new ConcurrentHashMap<>();
    public static FireParameter allPara97 = new FireParameter();


    public void init(){
        EventBusCenter.getEventBus().register(this);
    }

    @Resource
    private CollectDetector collectDetector;

    @Resource
    private CollectService collectService;

    @Resource
    private PortConf portConf;

    /**
     * 广播接收 串口通讯的数据
     *
     * @param preFireEvent 解析后的数据
     */
    @Subscribe
    public void eventReceiver(PreFireEvent preFireEvent) {
        /* 通信-串口通信 */
        if ("com".equals(preFireEvent.getType())){
            /* 串口-UPS */
            if ("1".equals(preFireEvent.getPort())){
                List<UpsFrameDto> list = preFireEvent.getEvent().getNewData();
                //此处接收串口或网口客户端回应代码,并处理
                UpsFrameDto upsFrameDto = list.get(0);
                byte[] fullBuff = upsFrameDto.getFullBuff();
                String instruction = preFireEvent.getEvent().getInstruction();
                instruction = instruction.replace(" ","");
                if ("51310D".equals(instruction)){
                    if (fullBuff[38] == 0x30) {
                        upsMode = 0;
                        log.info("表示市电正常，交流供电");
                    } else if (fullBuff[38] == 0x31) {
                        upsMode = 1;
                        log.info("市电异常，则电池供电");
                    }
                } else if ("51360D".equals(instruction)){
                    byte[] upsBatteryByte = new byte[]{fullBuff[82],fullBuff[83],fullBuff[84]};
                    upsBattery = Byte.parseByte(new String(upsBatteryByte));
                    log.info("当前ups电量为" + upsBattery);
                }

            } else if("10".equals(preFireEvent.getPort())){
                List<UpsFrameDto> newData = preFireEvent.getEvent().getNewData();
                byte[] fullBuff = newData.get(0).getFullBuff();
                String fullData = HexUtil.encodeHexStr(fullBuff);
                preFireRtuAnalysis(fullData,fullBuff);
            } else if ("COM5".equals(preFireEvent.getPort()) || "COM6".equals(preFireEvent.getPort())){
                String expectResults = preFireEvent.getEvent().getExpectResults();
                expectResults = expectResults.replace(" ","");
                byte[] bytes = coverData(expectResults);
//                byte[] bytes = HexUtil.decodeHex(expectResults);
                preFireRtuAnalysis(expectResults,bytes);
            } else {
                log.info("rtu -----> 未匹配到对应串口");
            }
        } /* 通信-网口通信 */
        else if ("tcp".equals(preFireEvent.getType())){
            String[] split = preFireEvent.getPort().split(":");
            String tcpIp = split[0];

            String tcpPortFire = portConf.getTcpPortFireOne();
            String[] split1 = tcpPortFire.split(":");
            /* 网口-Fire*/
            if (split1[0].equals(tcpIp)){
                List<byte[]> bytes = preFireEvent.getEvent().getNewData();
                byte[] bytes1 = bytes.get(0);
                String fullData = HexUtil.encodeHexStr(bytes1);
                String port = split[1];

                String instruction = preFireEvent.getEvent().getInstruction();

                /* 判断当前为哪个火前 */
                if ("10123".equals(port)){
                    preFireTcpAnalysis(fullData,bytes1);
                    log.info(port);
                } else if ("10125".equals(port)){
                    preFireTcpAnalysis(fullData,bytes1);
                    log.info(port);
                } else if ("10127".equals(port)){
                    preFireTcpAnalysis(fullData,bytes1);
                    log.info(port);
                } else if ("10129".equals(port)){
                    preFireTcpAnalysis(fullData,bytes1);
                    log.info(port);
                } else {
                    log.info("tcp-"+ tcpIp + "-ip未匹配到对应的port");
                }
            } else {
                log.info("tcp -----> 未匹配到对应网口");
            }
        } /* 通信-服务端消息 */
        else if ("server".equals(preFireEvent.getType())){
            String[] split = preFireEvent.getPort().split(":");
            String tcpIp = split[0];   // ip
//            if ("172.16.2.34".equals(tcpIp)){
            List<byte[]> bytes = preFireEvent.getEvent().getNewData();
            byte[] bytes1 = bytes.get(0);
            log.info(tcpIp + "----------------" + currentDemo(bytes1));
            String fullData = HexUtil.encodeHexStr(bytes1);
            preFireTcpAnalysis(fullData,bytes1);
//            }

        }else {
            log.info("-----eventbus-----当前无匹配数据");
        }
        System.out.println(Instant.now() +
                "监听者1-->回调1,收到事件：Com" + preFireEvent.getEvent().getPortKey() +
                "，线程号为：" + Thread.currentThread().getName());
    }

    public byte[] coverData(String hexData){
        byte[] bytes = new byte[hexData.length() / 2];
        int j = 0;
        for (int i = 0; i < bytes.length; i ++) {
            byte high = (byte) (Character.digit(hexData.charAt(j),16) & 0xff);
            byte low = (byte) (Character.digit(hexData.charAt(j+1),16) & 0xff);
            bytes[i] = (byte) (high << 4 | low);
            j += 2;
        }
        return bytes;
    }

    public void preFireTcpAnalysis(String fullData,byte[] bytes){
        /* 功能码为 */
        String cmdType = fullData.substring(10,12);
        switch (cmdType){
            case "02" -> {
                analysisCmdType66(bytes);
            }
            case "33" -> {
                analysisParamData(bytes);
//                analysisCmdType97(bytes);
            }
            case "9B" -> {
                analysisCmdType9B(bytes);
            }
            default -> log.info("未匹配到对应的功能码");
        }

    }

    public void preFireRtuAnalysis(String fullData,byte[] bytes){
        /* 功能码为 */
        String cmdType = fullData.substring(10,12);
        switch (cmdType){
            case "02" -> {
                analysisCmdType66(bytes);
            }
            case "33" -> {
                analysisParamData(bytes);
//                analysisCmdType97(bytes);
            }
            case "9B" -> {
                analysisCmdType9B(bytes);
            }
            default -> log.info("未匹配到对应的功能码");
        }

    }

    public static String currentDemo(byte[] bytes){
        log.info("数据测试---->bytes{}",bytes);
        // 0x11 U8 探测器时间戳
        String year = "20" + bytes[6];
        String mon = ByteHelper.padZeroLeft(bytes[7], 2);
        String day = ByteHelper.padZeroLeft(bytes[8], 2);
        String hour = ByteHelper.padZeroLeft(bytes[9], 2);
        String min = ByteHelper.padZeroLeft(bytes[10], 2);
        String sec = ByteHelper.padZeroLeft(bytes[11], 2);
        //        log.info("数据测试---->探测器时间{}",year + mon + day + hour + min + sec);

        byte[] deo = new byte[4];
        deo[0] = bytes[12];
        deo[1] = bytes[13];
        deo[2] = bytes[14];
        deo[3] = bytes[15];
        long l = ByteHelper.byteArrayToUInt(deo);
//        log.info("数据测试---->探测器心跳{},心跳转换时间{}", l , DateTimeHelper.secondToTimeString(l));
        String result = "数据测试---->探测器时间{" + (year + mon + day + hour + min + sec) + "}"
                + "数据测试---->探测器心跳{},心跳转换时间{" + l + "}" + DateTimeHelper.secondToTimeString(l);
        return result;
    }

    public void analysisCmdType66(byte[] bytes1){
        int index = 0;
        byte[] bsTemp;
        byte bTemp;
        boolean[] boolsTemp;
        if (bytes1 == null || bytes1.length == 0) return;

        byte[] bytes = new byte[1000];

        for (int i = 6; i < bytes1.length-2; i++) {
            bytes[i-6] = bytes1[i];
        }
        FireParameter allPara66 = new FireParameter();
        // 0x11 U8 探测器时间戳
        String year = "20" + bytes[index++];
        String mon = ByteHelper.padZeroLeft(bytes[index++], 2);
        String day = ByteHelper.padZeroLeft(bytes[index++], 2);
        String hour = ByteHelper.padZeroLeft(bytes[index++], 2);
        String min = ByteHelper.padZeroLeft(bytes[index++], 2);
        String sec = ByteHelper.padZeroLeft(bytes[index++], 2);
        allPara66.setTime(String.format("%s-%s-%s %s:%s:%s", year, mon, day, hour, min, sec));

        // 0x17 U32 探测器心跳
        bsTemp = new byte[4];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setHeartNum(ByteHelper.byteArrayToUInt(bsTemp));
        index += bsTemp.length;

        // 0x18 U8 探测器整机状态
        allPara66.setDetectorStatus(bytes[index++]);

        // 0x19 U16 各检测单元状态
        bsTemp = new byte[2];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setCheckUnitStatus(ByteHelper.byte2NumList(bsTemp));
        allPara66.setCheckUnitStatusValue((int) ByteHelper.byteArrayToShortLittle(bsTemp));
        index += bsTemp.length;

        // 0xEB U8 各检测模块使能标志 bit0-微粒子检测模块使能标识 bit1-烟雾检测模块使能标识
        bTemp = bytes[index++];
        boolsTemp = ByteHelper.byte2Boolean(bTemp);
        allPara66.setParticleModuleEnable(boolsTemp[7]);
        allPara66.setSmokeModuleEnable(boolsTemp[6]);

        // 0x1A U8 各检测模块整体状态 bit0-微粒子检测模块状态标识 bit1-烟雾检测模块状态标识
        bTemp = bytes[index++];
        bsTemp = ByteHelper.byte2NumList(bTemp);
        allPara66.setDetectorModuleStatus(bTemp);
        allPara66.setParticleModuleStatus(bsTemp[0]);
        allPara66.setSmokeModuleStatus(bsTemp[1]);


        // 0x40 U8 1防区 报警状态
        byte warnStatus = bytes[index++];
        allPara66.setAlarmStatus1(warnStatus);

        // 0x41 U32 1 防区微粒子数量
        bsTemp = new byte[4];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setParticleCount1(ByteHelper.byteArrayToUInt(bsTemp));
        index += bsTemp.length;


        // 0x42 float 1防区 微粒子浓度百分比
        bsTemp = new byte[4];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setParticlePercent1(FloatHelper.round(ByteHelper.byteArrayToFloatLittleEndian(bsTemp), 1));
        index += bsTemp.length;


        // 0x43 U32 1 防区 烟雾检测数据
        bsTemp = new byte[4];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setSmokeCount1(ByteHelper.byteArrayToUInt(bsTemp));
        index += bsTemp.length;

        // 0x44 float 1 防区 烟雾浓度百分比
        bsTemp = new byte[4];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setSmokePercent1(FloatHelper.round(ByteHelper.byteArrayToFloatLittleEndian(bsTemp), 1));
        index += bsTemp.length;

        // 0x21 U16 供电电压
        bsTemp = new byte[2];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setServiceVoltage(ByteHelper.byteArrayToUInt(bsTemp) * 0.01f);
        index += bsTemp.length;

        // 0xEA U8 各流速传感器使能标志
        bTemp = bytes[index++];
        boolsTemp = ByteHelper.byte2Boolean(bTemp);
        allPara66.setFlowSensorEnable(boolsTemp);

        // 0x22 U8 采样管 1 流速
        allPara66.setSamplingFlow1(bytes[index++]);

        // 0x23 U8 采样管 2 流速
        allPara66.setSamplingFlow2(bytes[index++]);

        // 0x24 U8 采样管 3 流速
        allPara66.setSamplingFlow3(bytes[index++]);

        // 0x25 U8 采样管 4 流速
        allPara66.setSamplingFlow4(bytes[index++]);

        // 0x26 S16 环境温度
        bsTemp = new byte[2];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setEnvTemperature(ByteHelper.byteArrayToShortLittle(bsTemp) * 0.01f);
        index += bsTemp.length;

        // 0x27 U16 环境湿度
        bsTemp = new byte[2];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setEnvHumidity(ByteHelper.byteArrayToUInt(bsTemp) * 0.01f);
        index += bsTemp.length;

        // 0x28 U16 真空压力
        bsTemp = new byte[2];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setVacuumPressure(ByteHelper.byteArrayToUInt(bsTemp) * 0.01f);
        index += bsTemp.length;

        // 0x29 U16 PD 探测电压
        bsTemp = new byte[2];
        System.arraycopy(bytes, index, bsTemp, 0, bsTemp.length);
        allPara66.setDetectPressure(ByteHelper.byteArrayToUInt(bsTemp) * 0.01f);
        index += bsTemp.length;

        // 0x2A U8 开关量输入状态
        bTemp = bytes[index++];
        bsTemp = ByteHelper.byte2NumList(bTemp);
        allPara66.setDiStatus(bsTemp);

        // 0x2B U8 开关量输出状态  //6-27
        bTemp = bytes[index++];
        bsTemp = ByteHelper.byte2NumList(bTemp);
        allPara66.setDoStatus(bsTemp);

        // 0x1B 静音报警声音 0：正常（非静音） false ;1：静音 true
        allPara66.setMuteAlarmSound(bytes[index++] == 0x01);//6-14

        if (SysHelper.debug){
            // 测试模拟数据
            allPara66.setAlarmStatus1((byte) RandomUtil.randomInt(0, 5)); // 测试，正式请删除
            allPara66.setParticlePercent1(RandomUtil.randomInt(0, 100)); // 测试，正式请删除
            allPara66.setSmokePercent1(RandomUtil.randomInt(0, 100)); // 测试，正式请删除
        }

        for (MemDevice value : collectService.memDeviceList.values()) {
            if (value.getDetectorAddr()==bytes1[4]) {
                log.info("value.getDetectorAddr()==bytes1[4]{}----->{}", value.getDetectorAddr(), bytes1[4]);
                /* 更新数据 */
                try {
                    currentTime.put(value.getArea1Id(),System.currentTimeMillis() + "");
                    collectDetector.updateMemInfo(value, allPara66);
                    collectDetector.updateDbInfo(value, allPara66);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

        }
    }

    public void analysisParamData(byte[] bytes){
        FireDto fullDto = new FireDto();
        // 非加密帧 0x55，加密帧 0xA5
        fullDto.setEncrypted(bytes[0] == (byte) 0xA5);

        byte len = bytes[1]; // 有效载荷长度
        fullDto.setDataLen(len);

        fullDto.setSeq(bytes[2]);

        fullDto.setSysId(bytes[3]);

        fullDto.setCompId(bytes[4]);

        fullDto.setCmdType(bytes[5]);

        byte[] bytes1 = new byte[len];
        System.arraycopy(bytes, 6, bytes1, 0, len);
        fullDto.setUnitBuff(bytes1);

        GetParamList(fullDto);
    }

    public void analysisCmdType9B(byte[] bytes){
        int index = 0;
        byte[] byteUnit = new byte[bytes[1]];
        System.arraycopy(bytes, 6, byteUnit, 0, byteUnit.length);
        while (index < bytes[1]) {
            // 参数序号
            Byte paramNo = byteUnit[index];
            index++;
            // 设置结果
            Byte res = byteUnit[index];
            index++;
            allPara9B.put(paramNo, res);
        }
    }

    private List<SingleParaInfo> GetParamList(FireDto respDto) {
        List<SingleParaInfo> paraList = new ArrayList<>();
        int index = 0;
        while (index < respDto.getDataLen()) {
            SingleParaInfo paraInfo = new SingleParaInfo();
            // 参数序号
            paraInfo.setId(respDto.getUnitBuff()[index]);
            index++;
            // 数据部分字节长度（0:无数据,因不支持或者异常）
            paraInfo.setLength(respDto.getUnitBuff()[index]);
            index++;
            if (paraInfo.getLength() == 0) continue;
            // 数据
            byte[] data = new byte[paraInfo.getLength()];
            System.arraycopy(respDto.getUnitBuff(), index, data, 0, data.length);
            paraInfo.setData(data);
            index += paraInfo.getLength();

            paraList.add(paraInfo);
        }
        analysisCmdType97(paraList);
        return paraList;
    }
    public void analysisCmdType97(List<SingleParaInfo> paraList){

        FireParameter allPara = new FireParameter();
        for (SingleParaInfo paraInfo : paraList) {
            if (paraInfo.getLength() == 0) continue;

            byte[] bsTemp;
            boolean[] bListTemp;
            // 0x01 产品类型 产品大类例：ZHLW HFD
            // 0x02 产品型号 产品具体型号例 ZHLW12-5
            // 0x03 设备编号 U32 例：49 00 00 00 参数值，显示值为 73
            switch (paraInfo.getId()) {
                case 0x01 -> allPara.setProductType(ByteHelper.bytesToAscii(paraInfo.getData()));
                case 0x02 -> allPara.setProductModelText(ByteHelper.bytesToAscii(paraInfo.getData()));
                case 0x13 -> allPara.setOutputRelayCtrl1(paraInfo.getData()[0]);
                case 0x14 -> allPara.setOutputRelayCtrl2(paraInfo.getData()[0]);
                case 0x15 -> allPara.setOutputRelayCtrl3(paraInfo.getData()[0]);
                case 0x16 -> allPara.setOutputRelayCtrl4(paraInfo.getData()[0]);
                case (byte) 0xA0 -> allPara.setSensitivity(paraInfo.getData()[0]);
                case (byte) 0xA1 -> allPara.setFareAlarmThresholdValue(paraInfo.getData()[0]);
                case (byte) 0xA2 -> allPara.setFareAlarmThresholdValue3(paraInfo.getData()[0]);
                case (byte) 0xA3 -> allPara.setFareAlarmThresholdValue2(paraInfo.getData()[0]);
                case (byte) 0xA4 -> allPara.setFareAlarmThresholdValue1(paraInfo.getData()[0]);
                case (byte) 0xA5 -> allPara.setSampling1HighLimit(paraInfo.getData()[0]);
                case (byte) 0xA6 -> allPara.setSampling2HighLimit(paraInfo.getData()[0]);
                case (byte) 0xA7 -> allPara.setSampling3HighLimit(paraInfo.getData()[0]);
                case (byte) 0xA8 -> allPara.setSampling4HighLimit(paraInfo.getData()[0]);
                case (byte) 0xA9 -> allPara.setFanSpeed(paraInfo.getData()[0]);
                case (byte) 0xAC -> allPara.setInput1(paraInfo.getData()[0]);
                case (byte) 0xAD -> allPara.setInput2(paraInfo.getData()[0]);
                case (byte) 0xAE -> allPara.setInput3(paraInfo.getData()[0]);
                case (byte) 0xAF -> allPara.setInput4(paraInfo.getData()[0]);
                case (byte) 0xB0 -> {
                    bsTemp = ByteHelper.byte2NumList(paraInfo.getData()[0]);
                    allPara.setInput1Status(bsTemp[0]);
                    allPara.setInput2Status(bsTemp[1]);
                    allPara.setInput3Status(bsTemp[2]);
                    allPara.setInput4Status(bsTemp[3]);
                }
                case (byte) 0xB1 -> allPara.setOutput1(paraInfo.getData()[0]);
                case (byte) 0xB2 -> allPara.setOutput2(paraInfo.getData()[0]);
                case (byte) 0xB3 -> allPara.setOutput3(paraInfo.getData()[0]);
                case (byte) 0xB4 -> allPara.setOutput4(paraInfo.getData()[0]);
                case (byte) 0xB5 -> allPara.setOutput1Delay(paraInfo.getData()[0]);
                case (byte) 0xB6 -> allPara.setOutput2Delay(paraInfo.getData()[0]);
                case (byte) 0xB7 -> allPara.setOutput3Delay(paraInfo.getData()[0]);
                case (byte) 0xB8 -> allPara.setOutput4Delay(paraInfo.getData()[0]);
                case (byte) 0xB9 -> {
                    bsTemp = ByteHelper.byte2NumList(paraInfo.getData()[0]);
                    allPara.setOutput1Status(bsTemp[0]);
                    allPara.setOutput2Status(bsTemp[1]);
                    allPara.setOutput3Status(bsTemp[2]);
                    allPara.setOutput4Status(bsTemp[3]);
                }
                case (byte) 0xBA -> allPara.setAlarmVolume(paraInfo.getData()[0]);
                case (byte) 0xBB -> allPara.setBgConcentration(paraInfo.getData()[0]);
                case (byte) 0xBC -> allPara.setSampling1LowLimit(paraInfo.getData()[0]);
                case (byte) 0xBD -> allPara.setSampling2LowLimit(paraInfo.getData()[0]);
                case (byte) 0xBE -> allPara.setSampling3LowLimit(paraInfo.getData()[0]);
                case (byte) 0xBF -> allPara.setSampling4LowLimit(paraInfo.getData()[0]);
                case (byte) 0xC0 -> allPara.setCommModel(paraInfo.getData()[0]);
                case (byte) 0xC1 -> allPara.setDeviceAddr(paraInfo.getData()[0]);
                case (byte) 0xC2 -> allPara.setBaudRate(ByteHelper.byteArrayToIntLittle(paraInfo.getData()));
                case (byte) 0xE0 -> allPara.setAreaCount(paraInfo.getData()[0]);
                case (byte) 0xE1 -> allPara.setFlowRateCheckFactor1(paraInfo.getData()[0]);
                case (byte) 0xE2 -> allPara.setFlowRateCheckFactor2(paraInfo.getData()[0]);
                case (byte) 0xE3 -> allPara.setFlowRateCheckFactor3(paraInfo.getData()[0]);
                case (byte) 0xE4 -> allPara.setFlowRateCheckFactor4(paraInfo.getData()[0]);
                case (byte) 0xE5 ->
                        allPara.setPdDetectVoltageValue(ByteHelper.byteArrayToFloatLittleEndian(paraInfo.getData()));
                case (byte) 0xE6 -> allPara.setWaterLevelLimit(ByteHelper.byteArrayToIntLittle(paraInfo.getData()));
                case (byte) 0xE7 -> allPara.setSmokeLimit(ByteHelper.byteArrayToIntLittle(paraInfo.getData()));
                case (byte) 0xE8 -> allPara.setSignBaseValue(ByteHelper.byteArrayToIntLittle(paraInfo.getData()));
                case (byte) 0xE9 -> allPara.setProductModel(paraInfo.getData()[0]);
                case (byte) 0xEA -> {
                    bListTemp = ByteHelper.byte2Boolean(paraInfo.getData()[0]);
                    allPara.setFlowSpeedSensorEnable1(bListTemp[0]);
                    allPara.setFlowSpeedSensorEnable2(bListTemp[1]);
                    allPara.setFlowSpeedSensorEnable3(bListTemp[2]);
                    allPara.setFlowSpeedSensorEnable4(bListTemp[3]);
                }
                case (byte) 0xEB -> {
                    bListTemp = ByteHelper.byte2Boolean(paraInfo.getData()[0]);
                    allPara.setParticleModuleEnable(bListTemp[0]);
                    allPara.setSmokeModuleEnable(bListTemp[1]);
                }
            }
        }
        allPara97 = allPara;
    }
    //    public void analysisCmdType97(byte[] bytes){
//
//        byte[] bsTemp;
//        boolean[] bListTemp;
//        // 0x01 产品类型 产品大类例：ZHLW HFD
//        // 0x02 产品型号 产品具体型号例 ZHLW12-5
//        // 0x03 设备编号 U32 例：49 00 00 00 参数值，显示值为 73
//        switch (bytes[5]) {
//            case 0x01 -> allPara97.setProductType(ByteHelper.bytesToAscii(bytes));
//            case 0x02 -> allPara97.setProductModelText(ByteHelper.bytesToAscii(bytes));
//            case 0x13 -> allPara97.setOutputRelayCtrl1(bytes[0]);
//            case 0x14 -> allPara97.setOutputRelayCtrl2(bytes[0]);
//            case 0x15 -> allPara97.setOutputRelayCtrl3(bytes[0]);
//            case 0x16 -> allPara97.setOutputRelayCtrl4(bytes[0]);
//            case (byte) 0xA0 -> allPara97.setSensitivity(bytes[0]);
//            case (byte) 0xA1 -> allPara97.setFareAlarmThresholdValue(bytes[0]);
//            case (byte) 0xA2 -> allPara97.setFareAlarmThresholdValue3(bytes[0]);
//            case (byte) 0xA3 -> allPara97.setFareAlarmThresholdValue2(bytes[0]);
//            case (byte) 0xA4 -> allPara97.setFareAlarmThresholdValue1(bytes[0]);
//            case (byte) 0xA5 -> allPara97.setSampling1HighLimit(bytes[0]);
//            case (byte) 0xA6 -> allPara97.setSampling2HighLimit(bytes[0]);
//            case (byte) 0xA7 -> allPara97.setSampling3HighLimit(bytes[0]);
//            case (byte) 0xA8 -> allPara97.setSampling4HighLimit(bytes[0]);
//            case (byte) 0xA9 -> allPara97.setFanSpeed(bytes[0]);
//            case (byte) 0xAC -> allPara97.setInput1(bytes[0]);
//            case (byte) 0xAD -> allPara97.setInput2(bytes[0]);
//            case (byte) 0xAE -> allPara97.setInput3(bytes[0]);
//            case (byte) 0xAF -> allPara97.setInput4(bytes[0]);
//            case (byte) 0xB0 -> {
//                bsTemp = ByteHelper.byte2NumList(bytes[0]);
//                allPara97.setInput1Status(bsTemp[0]);
//                allPara97.setInput2Status(bsTemp[1]);
//                allPara97.setInput3Status(bsTemp[2]);
//                allPara97.setInput4Status(bsTemp[3]);
//            }
//            case (byte) 0xB1 -> allPara97.setOutput1(bytes[0]);
//            case (byte) 0xB2 -> allPara97.setOutput2(bytes[0]);
//            case (byte) 0xB3 -> allPara97.setOutput3(bytes[0]);
//            case (byte) 0xB4 -> allPara97.setOutput4(bytes[0]);
//            case (byte) 0xB5 -> allPara97.setOutput1Delay(bytes[0]);
//            case (byte) 0xB6 -> allPara97.setOutput2Delay(bytes[0]);
//            case (byte) 0xB7 -> allPara97.setOutput3Delay(bytes[0]);
//            case (byte) 0xB8 -> allPara97.setOutput4Delay(bytes[0]);
//            case (byte) 0xB9 -> {
//                bsTemp = ByteHelper.byte2NumList(bytes[0]);
//                allPara97.setOutput1Status(bsTemp[0]);
//                allPara97.setOutput2Status(bsTemp[1]);
//                allPara97.setOutput3Status(bsTemp[2]);
//                allPara97.setOutput4Status(bsTemp[3]);
//            }
//            case (byte) 0xBA -> allPara97.setAlarmVolume(bytes[0]);
//            case (byte) 0xBB -> allPara97.setBgConcentration(bytes[0]);
//            case (byte) 0xBC -> allPara97.setSampling1LowLimit(bytes[0]);
//            case (byte) 0xBD -> allPara97.setSampling2LowLimit(bytes[0]);
//            case (byte) 0xBE -> allPara97.setSampling3LowLimit(bytes[0]);
//            case (byte) 0xBF -> allPara97.setSampling4LowLimit(bytes[0]);
//            case (byte) 0xC0 -> allPara97.setCommModel(bytes[0]);
//            case (byte) 0xC1 -> allPara97.setDeviceAddr(bytes[0]);
//            case (byte) 0xC2 -> allPara97.setBaudRate(ByteHelper.byteArrayToIntLittle(bytes));
//            case (byte) 0xE0 -> allPara97.setAreaCount(bytes[0]);
//            case (byte) 0xE1 -> allPara97.setFlowRateCheckFactor1(bytes[0]);
//            case (byte) 0xE2 -> allPara97.setFlowRateCheckFactor2(bytes[0]);
//            case (byte) 0xE3 -> allPara97.setFlowRateCheckFactor3(bytes[0]);
//            case (byte) 0xE4 -> allPara97.setFlowRateCheckFactor4(bytes[0]);
//            case (byte) 0xE5 ->
//                    allPara97.setPdDetectVoltageValue(ByteHelper.byteArrayToFloatLittleEndian(bytes));
//            case (byte) 0xE6 -> allPara97.setWaterLevelLimit(ByteHelper.byteArrayToIntLittle(bytes));
//            case (byte) 0xE7 -> allPara97.setSmokeLimit(ByteHelper.byteArrayToIntLittle(bytes));
//            case (byte) 0xE8 -> allPara97.setSignBaseValue(ByteHelper.byteArrayToIntLittle(bytes));
//            case (byte) 0xE9 -> allPara97.setProductModel(bytes[0]);
//            case (byte) 0xEA -> {
//                bListTemp = ByteHelper.byte2Boolean(bytes[0]);
//                allPara97.setFlowSpeedSensorEnable1(bListTemp[0]);
//                allPara97.setFlowSpeedSensorEnable2(bListTemp[1]);
//                allPara97.setFlowSpeedSensorEnable3(bListTemp[2]);
//                allPara97.setFlowSpeedSensorEnable4(bListTemp[3]);
//            }
//            case (byte) 0xEB -> {
//                bListTemp = ByteHelper.byte2Boolean(bytes[0]);
//                allPara97.setParticleModuleEnable(bListTemp[0]);
//                allPara97.setSmokeModuleEnable(bListTemp[1]);
//            }
//        }
//    }
}
